use std::collections::HashSet;

struct Solution {}

fn main() {}

impl Solution {
    pub fn majority_element(nums: Vec<i32>) -> i32 {
        let mut element = nums[0];
        let mut ele_cnt = 1;
        for idx in 1..nums.len() {
            if element == nums[idx] {
                ele_cnt += 1;
                continue;
            }
            ele_cnt -= 1;
            if ele_cnt <= 0 {
                element = nums[idx];
                ele_cnt = 1;
            }
        }
        element
    }
}